package com.csh.szhm.adapter;

import com.csh.szhm.R;
import com.csh.szhm.utils.DebugUntil;

import android.content.Context;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class SzhmJfdhMainAdapter extends MyBaseAdapter<String> implements
		OnClickListener {

	public SzhmJfdhMainAdapter(Context c) {
		super(c);
		// TODO Auto-generated constructor stub
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return 10;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		HolderView holderView = null;
		if (convertView == null) {
			holderView = new HolderView();
			convertView = mLayoutInflater.inflate(R.layout.szhm_jf_item_layout,
					null);
			holderView.img = (ImageView) convertView
					.findViewById(R.id.szhm_jf_item_img_id);
			holderView.txt1 = (TextView) convertView
					.findViewById(R.id.szhm_jf_item_txt_1_id);
			holderView.txt2 = (TextView) convertView
					.findViewById(R.id.szhm_jf_item_txt_2_id);
			holderView.txt3 = (TextView) convertView
					.findViewById(R.id.szhm_jf_item_txt_3_id);
			holderView.txt4 = (TextView) convertView
					.findViewById(R.id.szhm_jf_item_txt_4_id);
			holderView.txt4.setOnClickListener(this);
			convertView.setTag(holderView);

		} else {
			holderView = (HolderView) convertView.getTag();
		}
		holderView.txt4.setTag(position);
		holderView.txt3.setText(getBuilder("100"));
		return convertView;
	}

	private SpannableStringBuilder mBuilder;
	private ForegroundColorSpan mRedSpan;

	private SpannableStringBuilder getBuilder(String name) {
		mBuilder = new SpannableStringBuilder("库存:" + name + "个");
		mRedSpan = new ForegroundColorSpan(mContext.getResources().getColor(
				R.color.main_text_color));
		mBuilder.setSpan(mRedSpan, 2, name.length() + 3,
				Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		return mBuilder;
	}

	private class HolderView {
		ImageView img;
		TextView txt1;
		TextView txt2;
		TextView txt3;
		TextView txt4;
	}

	@Override
	public void onClick(View v) {
		int pos = (Integer) v.getTag();
		DebugUntil.createInstance().toastStr("pos-->>" + pos);

	}
}
